import {
    getEmployeeList,

} from "@/apis/common.js";

import {
    orderCancel,
    getRepairView
} from "@/apis/workOrder.js";

import {
    deepClone
} from "@/util";

export default {
    data() {
        return {
            editId: '',
            cancelDescr: '',
            orderForm: {
                Descr: '', // 下单记录
                AppointmentDate: '',
                AppointmentTime: '',
                SalerCharge: '',
                RewardAmount: '',
                TGID: '',
                VirtCharge1: '',
                VirtCharge2: '',
                VirtCharge3: '',
                VirtCharge4: '',
                VirtCharge5: '',
                Employee1: '',
                Employee2: '',
                Employee3: '',
                Employee4: '',
                Employee5: '',
                CustId: '',
                CustName: '',
                Zone1: '',
                Zone2: '',
                Zone3: '',
                Tel: '', //电话
                Zone5: '',
                Contact: '', //联系人
                Zone1_2: '',
                Zone2_2: '',
                Zone3_2: '',
                Tel2: '',
                Zone5_2: '', //详细地址
                Contact2: '',
                CallPhotos: [],
                Remark1: '',
                Remark2: '',
                Remark3: '',
                Remark4: '',
                Remark5: '',
                ItemId: '',
                ItemName: '',
                ItemStyle: '',
                ItemBrand: '',
                ItemCatg: '',
                SerialNo: '',
                BuyDate: '',
                ExpaireDate: '',
                OrderSrc: '',
                OrderNo: '',        // 来源单号
                CustType: '',       // 客户类型
                RepairType: '',     //  服务类型
                Saler: '',          // 业务员
                Priority: false,
                RepairCatg: '',     // 服务分类
                lnkRegion: '',      //区域
            },
        };
    },
    // onPageScroll(res) {
    // 	console.log('onPageScroll', res)

    // },
    onLoad(option) {
        console.log('option', option)
        if (option.id) {
            this.editId = option.id
            this.fetchRepairView()
        }
    },
    methods: {
        async fetchRepairView() {
            const custTypeMap = {
                0: "",
                1: '公司',
                2: '家庭'
            }
            const res = await getRepairView({
                RepairId: this.editId
            })
            if (res.MsgCode != 0) return
            console.log('fetchRepairView------->', res)
            const orderForm = res.data
            orderForm.CustType = custTypeMap[res.data.CustType]
            orderForm.Descr = res.data.CallDescr
            orderForm.Expense01 = parseFloat(orderForm.Expense01)
            orderForm.Expense02 = parseFloat(orderForm.Expense02)
            orderForm.Expense03 = parseFloat(orderForm.Expense03)
            orderForm.Expense04 = parseFloat(orderForm.Expense04)
            orderForm.Expense05 = parseFloat(orderForm.Expense05)
            orderForm.Revenue01 = parseFloat(orderForm.Revenue01)
            orderForm.Revenue02 = parseFloat(orderForm.Revenue02)
            orderForm.Revenue03 = parseFloat(orderForm.Revenue03)
            orderForm.Revenue04 = parseFloat(orderForm.Revenue04)
            orderForm.Revenue05 = parseFloat(orderForm.Revenue05)
            orderForm.VirtCharge1 = parseFloat(orderForm.VirtCharge1)
            orderForm.VirtCharge2 = parseFloat(orderForm.VirtCharge2)
            orderForm.VirtCharge3 = parseFloat(orderForm.VirtCharge3)
            orderForm.VirtCharge4 = parseFloat(orderForm.VirtCharge4)
            orderForm.VirtCharge5 = parseFloat(orderForm.VirtCharge5)
            orderForm.SalerId = orderForm.Saler
            orderForm.Saler = orderForm.SalerName
            orderForm.Employee1 = orderForm.Engineer1Name
            orderForm.Employee2 = orderForm.Enginer2Name
            orderForm.Employee3 = orderForm.Enginer3Name
            orderForm.Employee4 = orderForm.Enginer4Name
            orderForm.Employee5 = orderForm.Enginer5Name

            delete orderForm.RepairDone
            delete orderForm.CreditDetail
            orderForm.CallPhotos = res.data.CallPhotos == '' ? [] : res.data.CallPhotos.split(',')
            this.imageList = orderForm.CallPhotos.map(item => {
                return { url: 'http://img.help10000.com' + item }
            })
            this.appointment = orderForm.AppointmentTime
            orderForm.lnkRegion = ''
            this.orderForm = orderForm

        },
        async handleOrderAdd() {
            const orderForm = deepClone(this.orderForm)
            const cancelDescr = this.cancelDescr
            if (!cancelDescr) return uni.showToast({
                title: '请填写消单原因',
                icon: "none",
                mask: true,
                position: "center",
            });

            const res = await orderCancel({
                RepairIds: orderForm.ID,
                Descr: cancelDescr
            })
            console.log('orderCancel res', res)

            if (res.MsgCode != 0) return
            uni.showToast({
                title: '消单成功',
                icon: "none",
                mask: true,
                position: "center",
            });
            setTimeout(() => {
                this.$navigateBack(this.$router, 1)
            }, 1000)

        },
    }
}
